﻿var modelid = jQuery.query.get("modelid");

Ext.onReady(function () {

    /*初始化快速提示*/
    Ext.QuickTips.init();
    /*将提示显示在form属性旁边*/
    Ext.form.Field.prototype.msgTarget = "qtip";
    /*定义数据模型*/
    var Info = new Ext.data.Record.create([
                        { name: 'ID', type: 'int', mapping: 'ID' },
                        { name: "ToStockRoomPepole", type: "string", mapping: "ToStockRoomPepole" },
                        { name: 'ToStockRoomContent', mapping: 'ToStockRoomContent' },
                        { name: 'ToStockRoomTime', type: 'date', mapping: 'ToStockRoomTime' },
                        { name: 'ToStockRoomExPepole', mapping: 'ToStockRoomExPepole' },
                        { name: 'ToStockRoomCount', type: 'int', mapping: 'ToStockRoomCount' },
                        { name: 'ToStockRoomExContent', type: 'string', mapping: 'ToStockRoomExContent' },
                        { name: 'ToStockRoomExState', type: 'int', mapping: 'ToStockRoomExState' },
                        { name: 'ToStockRoomExResult', type: 'string', mapping: 'ToStockRoomExResult' },
                        { name: "ToStockRoomName", type: "string", mapping: "ToStockRoomName" }
                        ]);

    /*创建数据源*/
    var groupStore = new Ext.data.GroupingStore({
        proxy: new Ext.data.HttpProxy({ url: "server/ToStockRoomStuff/ToStockRoomStuffList.aspx" }),
        reader: new Ext.data.JsonReader({ totalProperty: "Count", root: "List" }, Info),
        sortInfo: { field: 'ID', direction: 'DESC' }
    });

    /*设置每页条数*/
    var pageSize = 20;
    var cookiePageSize = parseInt(Ext.util.Cookies.get("pageSize"));
    if (cookiePageSize) { pageSize = cookiePageSize; }

    /*加载数据源*/
    groupStore.load({ params: { start: 0, limit: pageSize, type: 1, modelid: modelid} });

    /*创建选择列模型*/
    var sm = new Ext.grid.CheckboxSelectionModel();

    /*定义列模型*/
    var cm = new Ext.grid.ColumnModel([
            sm,
            { id: 'ID', header: '编号', dataIndex: 'ID', width: 60, sortable: true },
            { id: 'title', header: '物品名称', dataIndex: 'ToStockRoomName', width: 100, sortable: true },
            { id: 'adduser', header: '申请人', dataIndex: 'ToStockRoomPepole', width: 100, sortable: true },
            { id: 'addtime', header: '申请时间', dataIndex: 'ToStockRoomTime', width: 140, sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d') }
            ]);

    /*定义列模型*/
    var cm2 = new Ext.grid.ColumnModel([
            sm,
            { id: 'ID', header: '编号', dataIndex: 'ID', width: 60, sortable: true },
            { id: 'title', header: '物品名称', dataIndex: 'ToStockRoomName', width: 100, sortable: true },
            { id: 'addtime', header: '申请时间', dataIndex: 'ToStockRoomTime', width: 140, sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d') },
            { id: 'adduser', header: '申请人', dataIndex: 'ToStockRoomPepole', width: 100, sortable: true },
            { id: 'state', header: '申请结果', dataIndex: 'ToStockRoomExState', width: 140, sortable: true, renderer: function (v) { if (v == 2) { return "通过"; } else { return "退回"; } } }
            ]);

    /*创建下[每页行数]拉框*/
    var comboBox = new Ext.form.ComboBox({
        width: 50,
        typeAhead: true,
        triggerAction: 'all',
        lazyRender: true,
        mode: 'local',
        title: "每页行数",
        emptyText: pageSize,
        store: new Ext.data.ArrayStore({ id: 0, fields: ['myId', 'displayText'], data: [[10, 10], [20, 20], [30, 30], [50, 50], [100, 100]] }),
        valueField: 'myId',
        displayField: 'displayText'
    });
    comboBox.on("select", function (combo, record, index) {
        Ext.util.Cookies.set("pageSize", record.id);
        window.location.reload();
    });

    /*创建审核菜单*/

    //定义审核意见
    var ToStockRoomExContent = new Ext.form.HtmlEditor({
        fieldLabel: '审核意见', //标签名称 
        anchor: '100%',
        height: 100,
        name: "ToStockRoomExContent"
    });
    //定义申请说明
    var ToStockRoomContent = new Ext.form.TextArea({
        fieldLabel: '备注', //标签名称 
        anchor: '100%',
        height: 100,
        name: "ToStockRoomContent"
    });
    //审核面板
    var Exform = new Ext.form.FormPanel({
        expanded: false,
        frame: true,
        height: 270,
        width: 540,
        labelAlign: "right",
        labelWidth: 70,
        buttonAlign: "center",
        items: [{
            layout: 'column', //定义为列模式
            items: [{
                layout: 'form',
                columnWidth: .5,
                items: [{
                    xtype: 'textfield',
                    name: "ID",
                    fieldLabel: "物品编号",
                    width: 180,
                    disabled: true
                }]
            }, {
                columnWidth: .5,
                layout: 'form',
                items: [{
                    xtype: 'textfield',
                    name: "ToStockRoomName",
                    fieldLabel: "物品名称",
                    width: 180
                }]
            }]
        }, {//行2
            layout: 'column', //定义为列模式
            items: [{
                layout: 'form',
                columnWidth: .5,
                items: [{
                    xtype: 'textfield',
                    name: "ToStockRoomCount",
                    fieldLabel: "物品数量",
                    width: 180
                }]
            }, {
                layout: 'form',
                columnWidth: .5,
                items: [{
                    name: "PurchaseTime",
                    fieldLabel: "申请时间",
                    width: 180,
                    xtype: 'datefield',
                    format: "Y-m-d",
                    value: new Date()
                }]
            }]
        }, ToStockRoomContent, ToStockRoomExContent]
    });

    /*审核菜单窗口*/
    var Exwin = new Ext.Window({
        width: 550,
        border: false,
        title: "审核信息",
        items: Exform,
        iconCls: 'icon-search-16',
        buttonAlign: "center",
        buttons: [{
            iconCls: 'icon-search-16',
            text: "审核通过",
            handler: function () {
                if (Exform.form.isValid()) {
                    var params = {
                        ID: Exform.getForm().findField("ID").getValue(),
                        ToStockRoomName: Exform.getForm().findField("ToStockRoomName").getValue(),
                        ToStockRoomCount: Exform.getForm().findField("ToStockRoomCount").getValue(),
                        ToStockRoomContent: Exform.getForm().findField("ToStockRoomContent").getValue(),
                        ToStockRoomExContent: Exform.getForm().findField("ToStockRoomExContent").getValue(),
                        ToStockRoomExState: 2
                    };
                    Ext.Ajax.request({
                        url: "server/ToStockRoomStuff/ToStockRoomStuffExamine.aspx?modelid=" + modelid,
                        params: params,
                        success: function (response) {
                            var json = Ext.util.JSON.decode(response.responseText);
                            if (json.success) {
                                Ext.Msg.alert("申请成功", json.msg, function () {
                                    groupStore.load({ params: { start: 0, limit: pageSize, type: 1} });
                                });
                                form.getForm().reset();
                            } else {
                                Ext.Msg.alert("错误", json.msg);
                            }
                        },
                        failure: function (response) { Ext.Msg.alert("请求失败", response.responseText); }
                    });
                }
            }
        }, {
            text: "审核退回",
            handler: function () {
                if (Exform.form.isValid()) {
                    var params = {
                        ID: Exform.getForm().findField("ID").getValue(),
                        ToStockRoomName: Exform.getForm().findField("ToStockRoomName").getValue(),
                        ToStockRoomCount: Exform.getForm().findField("ToStockRoomCount").getValue(),
                        ToStockRoomContent: Exform.getForm().findField("ToStockRoomContent").getValue(),
                        ToStockRoomExContent: Exform.getForm().findField("ToStockRoomExContent").getValue(),
                        ToStockRoomExState: 3
                    };
                    Ext.Ajax.request({
                        url: "server/ToStockRoomStuff/ToStockRoomStuffExamine.aspx?modelid=" + modelid,
                        params: params,
                        success: function (response) {
                            var json = Ext.util.JSON.decode(response.responseText);
                            if (json.success) {
                                Ext.Msg.alert("申请成功", json.msg, function () {
                                    groupStore.load({ params: { start: 0, limit: pageSize, type: 1} });
                                });
                                form.getForm().reset();
                            } else {
                                Ext.Msg.alert("错误", json.msg);
                            }
                        },
                        failure: function (response) { Ext.Msg.alert("请求失败", response.responseText); }
                    });
                }
            }
        }],
        closeAction: "hide"
    });

    //采购申请
    var StockRoomName = new Ext.ux.ComboBoxTree({
        fieldLabel: "物品名称",
        hiddenName: "ParentIDss",
        name: "ParentID",
        width: 143,
        allowBlank: false, //不允许为空
        emptyText: "请选择",
        editable: false,
        selectNodeModel: 'all',
        tree: {
            xtype: 'treepanel',
            lines: true, rootVisible: false, border: false,
            loader: new Ext.tree.TreeLoader({ dataUrl: 'server/ToStockRoomStuff/StockRoomStuffName.aspx' }),
            root: new Ext.tree.AsyncTreeNode({ text: '选文件夹', id: "0", leaf: false })
        }
    });

    //采购申请
    var form = new Ext.form.FormPanel({
        region: 'south',
        title: "采购申请",
        margins: "0 5 5 0",
        collapsible: true,
        expanded: false,
        frame: true,
        split: false,
        height: 300,
        labelAlign: "right",
        labelWidth: 70,
        buttonAlign: "center",
        items: [{
            layout: 'column', //定义为列模式
            items: [{
                columnWidth: .3, //显示为第一列的宽度33%
                layout: 'form',
                items: [{
                    xtype: 'textfield', //显示为输入框
                    fieldLabel: '信息编号', //标签名称 
                    labelStyle: 'color:red', //标题的样式
                    minLength: 6,
                    minLengthText: "长度不能小于6个字符",
                    maxLength: 20,
                    maxLengthText: "长度超过了20个字符",
                    name: 'ID', //
                    allowBlank: false, //不允许为空
                    blankText: '信息编号不能为空', //不允许为空给的提示
                    regex: /[\u4e00-\u9fa5]/, //正则表达式在/...../之间.
                    regexText: "只能输入中文!", //正则表达式错误提示
                    anchor: '100%',
                    value: 0,
                    disabled: true
                }]
            },{ 
                columnWidth: .3, //显示为第一列的宽度33%
                layout: 'form',
                items: StockRoomName
            }, {
                columnWidth: .3, //显示为第一列的宽度33%
                layout: 'form',
                items: [{
                    xtype: 'textfield',
                    name: "ToStockRoomCount",
                    fieldLabel: "物品数量",
                    blankText: '物品数量不能为空',
                    regex: /^[1-9]\d*$/,
                    regexText: "只能输入数字!",
                    allowBlank: false,
                    anchor: '100%'
                }]
            }]
        },
                new Ext.form.HtmlEditor({
                    fieldLabel: '出库说明', //标签名称 
                    anchor: '100%',
                    name: "ToStockRoomContent"
                })],
        buttons: [
                { text: "确定", handler: function () {
                    if (form.form.isValid()) {
                        var params = {
                            ID: form.getForm().findField("ID").getValue(),
                            ToStockRoomName: StockRoomName.getCtValue(),
                            ToStockRoomCount: form.getForm().findField("ToStockRoomCount").getValue(),
                            ToStockRoomContent: form.getForm().findField("ToStockRoomContent").getValue(),
                            ToStockRoomExState: 0
                        };
                        Ext.Ajax.request({
                            url: "server/ToStockRoomStuff/ToStockRoomStuffApply.aspx?modelid=" + modelid,
                            params: params,
                            success: function (response) {
                                var json = Ext.util.JSON.decode(response.responseText);
                                if (json.success) {
                                    Ext.Msg.alert("请求成功", json.msg, function () {
                                        groupStore.load({ params: { start: 0, limit: pageSize, type: 1} });
                                    });
                                    form.getForm().reset();
                                } else {
                                    Ext.Msg.alert("错误", json.msg);
                                }
                            },
                            failure: function (response) { Ext.Msg.alert("请求失败", response.responseText); }
                        });
                    }
                }
                },
                { text: "重置", handler: function () { form.getForm().reset(); } }
                ]
    });

    /*创建数据窗格*/
    var grid1 = new Ext.grid.GridPanel({
        id: 1,
        title: "未审核",
        store: groupStore,
        autoExpandColumn: "title",
        view: new Ext.grid.GroupingView(),
        cm: cm,
        sm: sm,
        tbar: [{
            iconCls: 'icon-add',
            text: '采购申请',
            handler: function () {
                form.getForm().reset();
                viewport.items.get(1).expand();
            }
        }, {
            ref: '../ExamineBtn',
            iconCls: 'icon-del',
            text: '审核',
            disabled: true,
            handler: function (btn) {
                var list = grid1.getSelectionModel().getSelections();
                var itemid = list[0].get("ID");
                Exform.getForm().load({
                    url: "server/ToStockRoomStuff/ExamineStuffList.aspx",
                    params: { itemid: itemid },
                    method: "POST",
                    success: function (form, action) {
                        form.setValues(action.result);
                    },
                    failure: function (form, action) {
                        form.setValues(action.result);
                    }
                });
                Exwin.show();
            }

        }, {
            ref: '../removeBtn',
            iconCls: 'icon-del',
            text: '删除',
            disabled: true,
            handler: function () {
                Ext.MessageBox.confirm("确认提示", "确认要删除所选行数据？", function (btn) {
                    if (btn == "yes") {
                        var s = grid1.getSelectionModel().getSelections();
                        var delR = new Array();
                        var delRid = new Array();
                        for (var i = s.length - 1; i >= 0; i--) {
                            var r = s[i];
                            if (r.get('ID') != undefined) { delRid.push(r.get('ID')); delR.push(r); }
                        }
                        Ext.Ajax.request({
                            url: "server/ToStockRoomStuff/ToStockRoomStuffDel.aspx?modelid=" + modelid,
                            method: 'POST',
                            params: { id: delRid },
                            success: function (response) {
                                var json = Ext.util.JSON.decode(response.responseText);
                                if (json.success) {
                                    for (var i = 0; i < delR.length; i++) {
                                        if (json.ids.valueOf(delR[i].get('ID'))) { groupStore.remove(delR[i]) }
                                    }
                                    Ext.Msg.alert("提示", "已删除" + json.count + "行<br/>" + json.msg);
                                } else {
                                    Ext.Msg.alert("错误", json.msg);
                                }
                            }
                        });
                    }
                });
            }
        }, {
            ref: '../viewBtn',
            iconCls: 'icon-view',
            text: '查看',
            disabled: true,
            handler: function (btn) {
                var grid1items = grid1.getSelectionModel().getSelections();
                var item = grid1items[0].get("ID");
                window.open("server/ToStockRoomStuff/ToStockRoomStuffDetail.aspx?id2=" + item + "&Type=1");
            }
        }],
        bbar: new Ext.PagingToolbar({
            store: groupStore,
            pageSize: pageSize,
            displayInfo: true,
            prependButtons: true,
            items: [comboBox],
            displayMsg: "本页显示第{0}条到第{1}条数据，共{2}条",
            emptyMsg: "暂无记录"
        })
    });

    //出库面板
    var ToExform = new Ext.form.FormPanel({
        width: 350,
        frame: true,
        labelAlign: "right",
        buttonAlign: "right",
        labelWidth: 100,
        defaultType: "textfield",
        border: false,
        items: [
                        { name: "ID", fieldLabel: "库存物品编号", width: 180, blankText: '库存物品编号不能为空', regex: /^[1-9]\d*$/, regexText: "只能输入数字!", allowBlank: false },
                        { name: "ToStockRoomCount", fieldLabel: "材料物品数量", width: 180, blankText: '库存物品数量不能为空', regex: /^[1-9]\d*$/, regexText: "只能输入数字!", allowBlank: false }
                        ]
    });
    //出库窗口
    var ToExaminewin = new Ext.Window({
        border: false,
        width: 350,
        title: "出库",
        iconCls: 'icon-search-16',
        items: ToExform,
        buttonAlign: "center",
        buttons: [{
            iconCls: 'icon-search-16',
            text: "出库",
            handler: function () {
                if (ToExform.form.isValid()) {
                    var params = {
                        ID: ToExform.getForm().findField("ID").getValue(),
                        ToStockRoomCount: ToExform.getForm().findField("ToStockRoomCount").getValue()
                    };
                    Ext.Ajax.request({
                        url: "server/ToStockRoomStuff/ToStockRoomStuff.aspx?modelid=" + modelid,
                        params: params,
                        success: function (response) {
                            var json = Ext.util.JSON.decode(response.responseText);
                            if (json.success) {
                                Ext.Msg.alert("申请成功", json.msg, function () {
                                    groupStore.load({ params: { start: 0, limit: pageSize, type: 2} });
                                });
                                ToExform.getForm().reset();
                            } else {
                                Ext.Msg.alert("错误", json.msg);
                            }
                        },
                        failure: function (response) { Ext.Msg.alert("请求失败", response.responseText); }
                    });
                }
            }
        }, {
            text: "重置表单",
            handler: function () { ToExform.getForm().reset(); }
        }],
        closeAction: "hide"
    });




    /*创建重新申请采购菜单*/
    //定义审核意见
    var ToStockRoomExContent = new Ext.form.HtmlEditor({
        fieldLabel: '审核意见', //标签名称 
        anchor: '100%',
        height: 100,
        name: "ToStockRoomExContent"
    });
    //定义申请说明
    var ToStockRoomContent = new Ext.form.TextArea({
        fieldLabel: '备注', //标签名称 
        anchor: '100%',
        height: 100,
        name: "ToStockRoomContent"
    });
    //重新申请采购面板
    var Douform = new Ext.form.FormPanel({
        expanded: false,
        frame: true,
        height: 270,
        width: 540,
        labelAlign: "right",
        labelWidth: 70,
        buttonAlign: "center",
        items: [{
            layout: 'column', //定义为列模式
            items: [{
                layout: 'form',
                columnWidth: .5,
                items: [{
                    xtype: 'textfield',
                    name: "ID",
                    fieldLabel: "物品编号",
                    width: 180,
                    disabled: true
                }]
            }, {
                columnWidth: .5,
                layout: 'form',
                items: [{
                    xtype: 'textfield',
                    name: "ToStockRoomName",
                    fieldLabel: "物品名称",
                    width: 180
                }]
            }]
        }, {//行2
            layout: 'column', //定义为列模式
            items: [{
                layout: 'form',
                columnWidth: .5,
                items: [{
                    xtype: 'textfield',
                    name: "ToStockRoomCount",
                    fieldLabel: "物品数量",
                    width: 180
                }]
            }, {
                layout: 'form',
                columnWidth: .5,
                items: [{
                    name: "PurchaseTime",
                    fieldLabel: "申请时间",
                    width: 180,
                    xtype: 'datefield',
                    format: "Y-m-d",
                    value: new Date()
                }]
            }]
        }, ToStockRoomContent, ToStockRoomExContent]
    });

    /*重新申请采购窗口*/
    var Douwin = new Ext.Window({
        width: 550,
        border: false,
        title: "重新申请采购",
        items: Douform,
        iconCls: 'icon-search-16',
        buttonAlign: "center",
        buttons: [{
            iconCls: 'icon-search-16',
            text: "申请",
            handler: function () {
                if (Douform.form.isValid()) {
                    var params = {
                        ID: Douform.getForm().findField("ID").getValue(),
                        ToStockRoomName: Douform.getForm().findField("ToStockRoomName").getValue(),
                        ToStockRoomCount: Douform.getForm().findField("ToStockRoomCount").getValue(),
                        ToStockRoomContent: Douform.getForm().findField("ToStockRoomContent").getValue(),
                        ToStockRoomExState: 0
                    };
                    Ext.Ajax.request({
                        url: "server/ToStockRoomStuff/ToStockRoomStuffAgainApply.aspx?modelid=" + modelid,
                        params: params,
                        success: function (response) {
                            var json = Ext.util.JSON.decode(response.responseText);
                            if (json.success) {
                                Ext.Msg.alert("申请成功", json.msg, function () {
                                    groupStore.load({ params: { start: 0, limit: pageSize, type: 1} });
                                });
                                form.getForm().reset();
                            } else {
                                Ext.Msg.alert("错误", json.msg);
                            }
                        },
                        failure: function (response) { Ext.Msg.alert("请求失败", response.responseText); }
                    });
                }
            }
        }, {
            text: "重置",
            handler: function () {
                handler: function () { Douform.getForm().reset(); }
            }
        }],
        closeAction: "hide"
    });





    /*创建数据窗格*/
    var grid2 = new Ext.grid.GridPanel({
        id: 2,
        title: "已审核",
        store: groupStore,
        autoExpandColumn: "title",
        view: new Ext.grid.GroupingView(),
        cm: cm2,
        sm: sm,
        tbar: [{
            iconCls: 'icon-add',
            text: '重新申请采购',
            handler: function (btn) {
                var list = grid1.getSelectionModel().getSelections();
                var itemid = list[0].get("ID");
                Douform.getForm().load({
                    url: "server/ToStockRoomStuff/ExamineStuffList.aspx",
                    params: { itemid: itemid },
                    method: "POST",
                    success: function (form, action) {
                        form.setValues(action.result);
                    },
                    failure: function (form, action) {
                        form.setValues(action.result);
                    }
                });
                Douwin.show();
            }
        }, {
            iconCls: 'icon-del',
            text: '出库',
            handler: function (btn) {
                ToExaminewin.show();
            }

        }, {
            ref: '../removeBtn',
            iconCls: 'icon-del',
            text: '删除',
            disabled: true,
            handler: function () {
                Ext.MessageBox.confirm("确认提示", "确认要删除所选行数据？", function (btn) {
                    if (btn == "yes") {
                        var s = grid2.getSelectionModel().getSelections();
                        var delR = new Array();
                        var delRid = new Array();
                        for (var i = s.length - 1; i >= 0; i--) {
                            var r = s[i];
                            if (r.get('ID') != undefined) { delRid.push(r.get('ID')); delR.push(r); }
                        }
                        Ext.Ajax.request({
                            url: "server/ToStockRoomStuff/ToStockRoomStuffDel.aspx?modelid=" + modelid,
                            method: 'POST',
                            params: { id: delRid },
                            success: function (response) {
                                var json = Ext.util.JSON.decode(response.responseText);
                                if (json.success) {
                                    for (var i = 0; i < delR.length; i++) {
                                        if (json.ids.valueOf(delR[i].get('ID'))) { groupStore.remove(delR[i]) }
                                    }
                                    Ext.Msg.alert("提示", "已删除" + json.count + "行<br/>" + json.msg);
                                } else {
                                    Ext.Msg.alert("错误", json.msg);
                                }
                            }
                        });
                    }
                });
            }
        }, {
            ref: '../viewBtn',
            iconCls: 'icon-view',
            text: '查看',
            disabled: true,
            handler: function (btn) {
                var grid1items = grid2.getSelectionModel().getSelections();
                var item = grid1items[0].get("ID");
                window.open("server/ToStockRoomStuff/ToStockRoomStuffDetail.aspx?id2=" + item);
                //                        var list = grid2.getSelectionModel().getSelections();
                //                        var win = new Ext.Window({
                //                            border: false,
                //                            title: "详细信息",
                //                            autoLoad: { url: "server/Purchase/PurchaseDetail.aspx", scripts: true, params: { 'id2': list[0].get("ID"), 'modelid': modelid} },
                //                            iconCls: 'icon-search-16',
                //                            buttonAlign: "center",
                //                            buttons: [{
                //                                iconCls: 'icon-search-16',
                //                                text: "关闭",
                //                                handler: function () {

                //                                }
                //                            }],
                //                            closeAction: "hide"
                //                        });

                //                        win.show();
            }
        }],
        bbar: new Ext.PagingToolbar({
            store: groupStore,
            pageSize: pageSize,
            displayInfo: true,
            prependButtons: true,
            items: [comboBox],
            displayMsg: "本页显示第{0}条到第{1}条数据，共{2}条",
            emptyMsg: "暂无记录"
        })
    });

    var tabpanel = new Ext.TabPanel({
        border: false,
        region: "center",
        activeTab: 0,    //设置默认选择的选项卡
        items: [grid1, grid2]
    });

    tabpanel.on("beforetabchange", function (tab, ntab, ctab) {
        groupStore.load({ params: { start: 0, limit: 10, type: ntab.id} });
    });

    var viewport = new Ext.Viewport({
        enableTabScroll: true,
        layout: "border",
        items: [tabpanel, form]
    });
    viewport.items.get(1).collapse();
    viewport.doLayout();

    /*延时加载*/
    setTimeout(function () { Ext.get('loading').remove(); Ext.get('loading-mask').fadeOut({ remove: true }); }, 400);

    /*grid1有选择行启用删除按钮*/
    grid1.getSelectionModel().on('selectionchange', function (sm) {
        grid1.removeBtn.setDisabled(sm.getCount() < 1);
        grid1.viewBtn.setDisabled(sm.getCount() < 1 || sm.getCount() > 1);
        grid1.ExamineBtn.setDisabled(sm.getCount() < 1 || sm.getCount() > 1);
    });

    /*grid2有选择行启用删除按钮*/
    grid2.getSelectionModel().on('selectionchange', function (sm) {
        grid2.removeBtn.setDisabled(sm.getCount() < 1);
        grid2.viewBtn.setDisabled(sm.getCount() < 1 || sm.getCount() > 1);

    });
    grid1.on('rowclick', function (g, index, e) {
        viewport.items.get(1).expand();
        var r = g.getSelectionModel().getSelected();
        if (r != null) {
            form.setTitle("信息编辑");
            form.getForm().loadRecord(new Info({ 'ID': r.get("ID"), 'ParentIDss': r.get("ToStockRoomName"), 'ToStockRoomCount': r.get("ToStockRoomCount"), 'ToStockRoomContent': r.get("ToStockRoomContent") }));
            form.doLayout();
        }
    });
});